package com.baway.biliclitent.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.baway.biliclitent.R;
import com.baway.biliclitent.model.LiveBean;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 1.类的用途：
 * 2.作者：${赵渊} on 2017/3/10 11:30
 */
public class liveFragGridViewAdapter extends BaseAdapter{
    private  Context context;
    private List<LiveBean.DataBean.PartitionsBean.LivesBeanX> lives;

    public liveFragGridViewAdapter(Context context, List<LiveBean.DataBean.PartitionsBean.LivesBeanX> lives) {
        this.context = context;
        this.lives = lives;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder =  new ViewHolder();
            convertView = View.inflate(context, R.layout.item_live,null);
            holder.liveImage = (ImageView) convertView.findViewById(R.id.live_image);
            holder.liveName = (TextView) convertView.findViewById(R.id.live_name);
            holder.liveHeadImage = (ImageView) convertView.findViewById(R.id.item_live_user_cover);
            holder.item_live_count = (TextView) convertView.findViewById(R.id.item_live_count);
            holder.item_live_user = (TextView) convertView.findViewById(R.id.item_live_user);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(lives.get(position).getCover().getSrc()).into(holder.liveImage);
        Glide.with(context).load(lives.get(position).getOwner().getFace()).into(holder.liveHeadImage);
        holder.liveName.setText(lives.get(position).getTitle());
        holder.item_live_count.setText(lives.get(position).getOnline()+"");
        holder.item_live_user.setText(lives.get(position).getOwner().getName());
        return convertView;
    }
    class ViewHolder{
        ImageView liveImage;
        ImageView liveHeadImage;
        TextView  liveName;
        TextView item_live_count;
        TextView item_live_user;
    }
}
